package com.maxmlr.music.song.service.transfer;

import com.maxmlr.music.admin.entity.User;
import com.maxmlr.music.common.util.DateUtil;
import com.maxmlr.music.song.entity.Singer;
import com.maxmlr.music.song.entity.SingerProfiles;
import com.maxmlr.music.song.param.SingerInfoParam;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Objects;

/**
 * @ClassName SingerTransfer
 * @Description TODO
 * @Author maxiao
 * @Date 2020/6/7 下午10:24
 * @Version V1.0
 */
@Component
public class SingerTransfer {

    public SingerInfoParam po2SingerInfoParam(Singer singer, SingerProfiles singerProfiles) {
        SingerInfoParam singerInfoParam = po2SingerInfoParam(singer);
        singerInfoParam.setProfiles(singerProfiles.getProfiles());
        return singerInfoParam;
    }

    public SingerInfoParam po2SingerInfoParam(Singer singer) {
        SingerInfoParam singerInfoParam = new SingerInfoParam();
        singerInfoParam.setId(singer.getId());
        singerInfoParam.setSingerName(singer.getSingerName());
        singerInfoParam.setType(singer.getType());
        singerInfoParam.setNation(singer.getNation());
        singerInfoParam.setHeadImgId(singer.getHeadImgId());
        singerInfoParam.setCreateUserId(singer.getCreateUserId());
        singerInfoParam.setUpdateUserId(singer.getUpdateUserId());
        singerInfoParam.setCreateTime(DateUtil.getDateTimeStr(singer.getCreateTime()));
        singerInfoParam.setUpdateTime(DateUtil.getDateTimeStr(singer.getUpdateTime()));
        return singerInfoParam;
    }

    public Singer po2Singer(SingerInfoParam param, User adminUser) {
        Date date = DateUtil.getDate();
        Singer singer = new Singer();
        singer.setSingerName(param.getSingerName());
        singer.setType(param.getType());
        singer.setNation(param.getNation());
        singer.setHeadImgId(param.getHeadImgId());
        singer.setCreateUserId(adminUser.getId());
        singer.setUpdateUserId(adminUser.getId());
        singer.setCreateTime(date);
        singer.setUpdateTime(date);
        return singer;
    }

    public SingerProfiles po2SingerProfiles(Singer singer, SingerInfoParam param) {
        SingerProfiles singerProfiles = new SingerProfiles();
        singerProfiles.setSingerId(singer.getId());
        singerProfiles.setProfiles(param.getProfiles());
        singerProfiles.setCreateTime(singer.getCreateTime());
        singerProfiles.setUpdateTime(singer.getUpdateTime());
        return singerProfiles;
    }

    public void fullSinger(Singer singer, SingerInfoParam param, User adminUser) {
        Date date = DateUtil.getDate();
        singer.setSingerName(param.getSingerName());
        singer.setType(param.getType());
        singer.setNation(param.getNation());
        singer.setHeadImgId(param.getHeadImgId());
        singer.setUpdateUserId(adminUser.getId());
        singer.setUpdateTime(date);
    }

    public void fullSingerProfiles(SingerProfiles singerProfiles, SingerInfoParam param, Singer singer) {
        if (Objects.isNull(singerProfiles)) {
            singerProfiles = new SingerProfiles();
            singerProfiles.setSingerId(singer.getId());
            singerProfiles.setCreateTime(singer.getCreateTime());
        }
        singerProfiles.setProfiles(param.getProfiles());
        singerProfiles.setUpdateTime(singer.getUpdateTime());
    }
}
